<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Event {
    private $ci;

    public function __construct(){
        $this->ci = &get_instance();
    }

    public function sendMail($aInfo) {
        //send email
        $this->ci->load->library('MyPHPMailer');
        $mail = $this->ci->myphpmailer->config();
        $mail->Subject = $aInfo['subject'];
        $mail->Body = $this->ci->load->view($aInfo['template'], $aInfo['data'], true);
        $mail->AddAddress($aInfo['email'], $aInfo['email']);
        $mail->AddAddress($aInfo['email'], $aInfo['email']);

        //Must embeded logo first
        $mail->addEmbeddedImage(get_attachment('images/logo.png', 'common'), 'logo', 'logo');
        if(isset($aInfo['attachment']) && count($aInfo['attachment'])>0){
            foreach($aInfo['attachment'] as $name=>$at){
                $mail->AddEmbeddedImage($at, $name, $name);
            }
        }
        return $mail->Send();
    }
}
?>